package com.mzy.linear_struct.hot100.栈;

import java.util.*;

/**
 * @Author: mizy3
 * @Date: 2024/08/11/下午3:28
 * @Description:
 */
public class Pro739每日温度 {
    private int[] dailyTemperatures(int[] temperatures) {

        Deque<Integer> stack = new LinkedList<>();

        int[] ans = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++) {
            while (!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i]){
                Integer pop = stack.pop();
                ans[pop] = i - pop;
            }
            stack.push(i);
        }


        return ans;
    }
    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Pro739每日温度().dailyTemperatures(new int[]{73, 74, 75, 71, 69, 72, 76, 73})));
    }
}



















